import Vue from 'vue';
import App from './App';
import store from './store';
import customTabbar from '@/components/custom-tabbar.vue';
Vue.component("custom-tabbar", customTabbar);

import httpInterceptor from '@/common/http.interceptor.js';
Vue.config.productionTip = false;
Vue.prototype.$store = store;
Vue.prototype.$timer = null;

import { marked } from "./common/tool.js";

App.mpType = 'app';

const app = new Vue({
	store,
	...App
});

// 引入全局uView
import uView from 'uview-ui';
Vue.use(uView);
Vue.use(httpInterceptor, app);

import Notice from '@/components/notice.vue';
Vue.component("Notice", Notice)

Vue.mixin({
  methods: {
    marked(arr, str){
			if(!arr.length){
				return str;
			}else{
				let html = str;
				arr.map(item=>{
					if(!!item){
						item = item.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 
						let reg = new RegExp(item, "g");
						html = html.replace(reg, `<b class='sjgjc' style='color: #FD5E3A'>${item}</b>`);
					}
				});
				return html;
			}
    }
  }
});

Vue.prototype.$clearStorage = function () {
	uni.removeStorageSync("token");
	uni.removeStorageSync("key");
	uni.removeStorageSync("own");
	uni.removeStorageSync("_key");
	uni.removeStorageSync("_iv");
	uni.removeStorageSync("userInfo");
	uni.removeStorageSync("copyTemplate");
	uni.removeStorageSync("usage");
	uni.removeStorageSync("warnData");
	uni.removeStorageSync("accounts");
};

uni.$zp = {
	config: {
		"auto": false,
		"auto-show-back-to-top": true,
		"back-to-top-bottom": "50rpx",
	}
}

uni.onNetworkStatusChange(function (res) {
	console.log("网络状态：", res.isConnected);
	console.log("网络类型：", res.networkType);
});

uni.$navBarRefresh = function() {
	// 80:专题监测 81:预警榜单 82:预警舆情 83:事件分析 84:站内搜索 85:溯源 86:舆情大屏
	const own = uni.getStorageSync("own");
	uni.setTabBarItem({
		index: 0,
		visible: own.includes(80) ? true :false,
		complete: (res)=>{
			console.log("callback", res)
		}
	});
	uni.setTabBarItem({
		index: 1,
		visible: own.includes(82) ? true :false
	});
	uni.setTabBarItem({
		index: 2,
		visible: own.includes(84) ? true :false
	});
	uni.setTabBarItem({
		index: 3,
		visible: own.includes(83) ? true :false
	});
}

app.$mount();